/**
 * CommunicationHandler.java
 * ************************** 
 * @date Mar 22, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package rmitut;

import java.rmi.RemoteException;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author michele
 * 
 * 
 * Description: 
 *
 */
public class CommunicationHandler {
	
	private static Deque<Message> receivedMessages = new ArrayDeque<Message>(100);
	private static Deque<Message> messagesToDispatch = new ArrayDeque<Message>(100);
	
	private CommunicationServer comServer = CommunicationServer.getComunicationServer(receivedMessages);;
	private MessageDispatcher msgDispatcher;
		
	public final CommunicationServer getComServer() {
		return comServer;
	}

	public final MessageDispatcher getMsgDispatcher() {
		return msgDispatcher;
	}

	public void startCommunicationHandler(String serviceName) {
//		comServer = CommunicationServer.getComunicationServer(receivedMessages);
		msgDispatcher = new MessageDispatcher(receivedMessages, messagesToDispatch);
		try {
			comServer.registryToRmiregistry(serviceName);
			msgDispatcher.start();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		System.out.println("Server is up");		
	}

}
